/*
 * CS_REQ_EVENT_DUNGEON_STAMINA_INFO_V2.cpp
 *
 *  Created on: 2014. 2. 12.
 *      Author: mega
 */

#include "../../User.h"
#include "../../NLogic/Stamina.h"
#include "../../NResource/Static.h"
#include "dungeon.h"

namespace ProjectZ { namespace NCommand { namespace NDungeon {

void CS_REQ_EVENT_DUNGEON_STAMINA_INFO_V2::OnExecute(User * pUser, ::Network::Packet * pPacket)
{
/*	CS_REQ_EVENT_DUNGEON_STAMINA_INFO_V2                  0x0834  //서버에 스태미너 정보 요청
	{

	}

	SC_REQ_EVENT_DUNGEON_STAMINA_INFO_V2                  0x0835
	{
	           s16 s16ack;                                                            //1: 성공
	           u8        u8stamina;                                                   //이벤트 던전 스태미너
	           u64      u64stamina_recovery_time;          //스태미너 회복까지 남은 시간 (초 단위).
	           u16      u16recovery_time;                              //스태미너 1회복하는데 필요한 시간 (분 단위)
	}*/


	PREPARE_PACKET;

	NLogic::Stamina * pStamina = pUser->GetStamina();
	if (NULL == pStamina)
	{
		DEBUGLOG("%s : pStamina is NULL!!!", __FUNCTION__);
		SendPacket(pUser, ACK_UNKNOWN_ERROR, 0, 0, 0);
		return;
	}

	int recoveryMinute = NResource::Static::InstancePtr()->GetStaminaResource()->GetRecoveryMinute(pUser);
	if (-1 == recoveryMinute)
	{
		DEBUGLOG("%s : recoveryMinute lookup fail", __FUNCTION__);
		SendPacket(pUser, ACK_UNKNOWN_ERROR, 0, 0, 0);
		return;
	}

	int64_t remainSec = pStamina->UpdateKeyRecoveryTime();

	SendPacket(pUser, ACK_OK, pStamina->GetCurrentKey(), remainSec, recoveryMinute);
}

void CS_REQ_EVENT_DUNGEON_STAMINA_INFO_V2::SendPacket(User * pUser, int res, int stamina, uint64_t remainSec, int recoveryMinute)
{
	::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();

	*pAck << static_cast<int16_t>(res);
	*pAck << static_cast<uint8_t>(stamina);
	*pAck << remainSec;
	*pAck << static_cast<uint16_t>(recoveryMinute);

	pAck->MakePacket(CMD_SC_REQ_EVENT_DUNGEON_STAMINA_INFO_V2);
	pUser->Send(pAck);
}

} /*NDungeon*/ } /*NCommand*/ } /*ProjectZ*/


